<div id="comment-list" class="admin container960">{{range .Comments}}
    <div class="comment clear" id="comment-{{.Id}}">
        <img class="c-avatar left" src="{{.Avatar}}" alt="{{.Author}}"/>
        <div class="c-section left">
            <div class="c-meta">
                <a class="lbl lbl-blue c-author{{if .IsAdmin}} admin{{end}}" href="{{.Url}}" target="_blank">{{.Author}}{{if .IsAdmin}}&nbsp;&nbsp;(admin){{end}}</a>
                <span class="c-time">{{DateInt64 .CreateTime "MM.DD HH:mm"}}</span>
                <span class="c-email">{{.Email}}</span>{{if .GetContent}}
                <span class="c-cnt">@{{.GetContent.Title}}</span>{{else}}
                <span class="c-cnt">@无效</span>{{end}}{{if ne .Status "approved"}}
                <a class="c-check" href="#" rel="{{.Id}}" title="审核">审核中</a>{{end}}
                <a class="c-reply" href="#" rel="{{.Id}}" title="回复">回复</a>
                <a class="c-del" href="#" rel="{{.Id}}" title="删除">删除</a>
            </div>
            <section class="c-content">{{Html .Content}}</section>{{if .ParentMd}}
            <div class="c-p-md markdown">{{Html .ParentMd}}</div>{{end}}
        </div>
    </div>{{end}}
    <ul id="article-pager" class="pager container960">{{range .Pager.PageSlice}}
        <li class="item{{if eq $.Pager.Current .}} current{{end}}"><a href="/admin/comments/?page={{.}}">{{.}}</a></li>{{end}}
    </ul>
    <form id="comment-form" action="/admin/comments/" class="form clear left" method="post">
        <textarea class="ipt left" name="content" id="comment-content" required="required"></textarea>
        <button class="btn btn-blue" id="comment-submit">回复评论</button>
        <button class="btn btn-green" id="comment-close">关闭回复</button>
        <input type="hidden" value="0" id="comment-parent" name="pid"/>
    </form>
</div>
<script>
    $(function () {
        $('.c-del').on("click", function () {
            if (confirm("删除评论将使相关内容无效!")) {
                var id = $(this).attr("rel");
                $.ajax({
                    type: "delete",
                    url: "/admin/comments/?id=" + id,
                    success: function (json) {
                        if (json.res) {
                            $('#comment-' + id).remove();
                        } else {
                            alert("删除失败");
                        }
                    }
                })
            }
            return false;
        });
        $('.c-check').on("click", function () {
            if (confirm("审核后此作者将不再标记审核!")) {
                var id = $(this).attr("rel");
                $.ajax({
                    type: "put",
                    url: "/admin/comments/?id=" + id,
                    success: function (json) {
                        if (json.res) {
                            $('#comment-' + id).find(".c-check").remove();
                        } else {
                            alert("审核失败");
                        }
                    }
                })
            }
            return false;
        });
        $('.c-reply').on("click",function(){
            var id = $(this).attr("rel");
            $('#comment-'+id).append($('#comment-form').detach().show());
            $('#comment-parent').val(id);
           return false;
        });
        $('#comment-form').ajaxForm(function(json){
            if(json.res){
                alert("已回复");
                window.location.href = "/admin/comments/";
            }else{
                alert("回复失败");
            }
        });
        $('#comment-close').on("click",function(){
            $('#comment-form').hide();
            $('#comment-parent').val(0);
            $('#comment-content').val("");
        })
    });
</script>